package com.emip.dao.impl;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.emip.bean.MinuteStoreBean;
import com.emip.dao.BaseDAO;
import com.emip.dao.MinuteStoreDAO;

@Repository("minuteStoreDAO")
public class MinuteStoreDAOImpl extends BaseDAO implements MinuteStoreDAO {

	final String SQLDATEFORMAT = "YYYY-MM-DD HH24:MI";
	
	public List<MinuteStoreBean> getByTimespan(String startDate, String endDate) {
		return this.getByTimespan(startDate, endDate, null);
	}

	@SuppressWarnings("unchecked")
	public List<MinuteStoreBean> getByTimespan(String startDate, String endDate, int[] items) {
		String hql = "from MinuteStoreBean entity where entity.genTime >= to_date('" + 
				startDate + "', '" + SQLDATEFORMAT + "') and " +
				"entity.genTime <= to_date('" + endDate + 
				"', '" + SQLDATEFORMAT + "')";
		if (items != null && items.length > 0) {
			hql += " and entity.item.id in " + Arrays.toString(items);
		}
		hql += " order by entity.genTime, entity.item.id";
		return this.getHibernateTemplate().find(hql);
	}
}
